package com.agrm.model.common.dtos;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 功能：
 *
 * @author 千堆雪
 * @version 1.0.0
 * created on 2025/1/27 12:19, last modified on 2025/1/27 12:19
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult<T> {
    private int code;//错误码
    private boolean success;//成功或失败的标志
    private String msg;//消息或错误
    private T data;//响应的数据


    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<T>(200, true, "操作成功", data);
    }

    public static JsonResult<Void> success() {
        return new JsonResult<Void>(200, true, "操作成功", null);
    }

    public static <T> JsonResult<T> fail(int code, String msg) {
        return new JsonResult<T>(code, false, msg, null);
    }

    public static <T> JsonResult<T> fail(String msg) {
        return fail(500, msg);
    }
}